#include "Input.h"

void Input::update()
{
	SDL_Event e;
	while (SDL_PollEvent(&e))
	{
		if (e.type == SDL_QUIT)
		{
			exit(0);
		}
		if (e.type == SDL_KEYDOWN)
		for (auto func: keyDownCallbacks)
		{
			func(e.key.keysym.sym);
		}
	}

	int len;
	auto keymap = SDL_GetKeyboardState(&len);
	for (auto func : scanKeyCallbacks)
	{
		func(keymap, len);
	}
}

void Input::addKeyDownCallback(KeyDownCallback func)
{
	keyDownCallbacks.push_back(func);
}

void Input::addScanKeyCallback(ScanKeyCallback func)
{
	scanKeyCallbacks.push_back(func);
}
